Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

deNet.hpp

Go to the documentation of this file.
00001 ///////////////////////////////////////////////////////////////////////////////
00002 /// @file deNet.hpp
00003 ///
00004 /// @brief Destiny3D networking system main header
00005 ///
00006 /// @author trajar
00007 ///
00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
00009 /// contents of this file is subject to the Destiny3D Member License which
00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
00011 ///
00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
00014 /// for any particular purpose.
00015 ///
00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
00017 ///
00018 /// <hr>
00019 ///                                 Change History
00020 /// <hr>
00021 ///
00022 /// @date Jun 2002
00023 /// @author trajar
00024 /// @remarks Creation
00025 ///
00026 ///////////////////////////////////////////////////////////////////////////////
00027 
00028 #ifndef _DENET_HPP
00029 #define _DENET_HPP
00030 
00031 #include "deGlobalTypes.hpp"
00032 
00033 #if defined(DENET_DLL_EXPORTS) || defined(DESTINY3D_EXPORT_ALL)
00034 #   define DENET_API _declspec(dllexport)
00035 #elif defined(DESTINY3D_STATIC_LINK)
00036 #   define DENET_API
00037 #else
00038 #   define DENET_API _declspec(dllimport)
00039 #endif
00040 
00041 // prevents inclusion in Winsock 1.1 structures
00042 #define _WINSOCKAPI_
00043 
00044 #pragma warning( disable : 4251 )
00045 #pragma warning( disable : 4786 )
00046 
00047 // Include some standard Windows defs
00048 typedef __int64             INT64;
00049 typedef unsigned char       BYTE;
00050 typedef unsigned long       DWORD;
00051 typedef unsigned short      WORD;
00052 typedef long                HRESULT;
00053 typedef unsigned int        WPARAM;
00054 typedef long                LPARAM;
00055 typedef long                LRESULT;
00056 
00057 #define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
00058 #define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
00059 #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
00060 
00061 #ifndef NULL
00062 #define NULL    0
00063 #endif
00064 
00065 //-------------------------------------------------
00066 // complie-time flags
00067 //
00068 // - DN_SESSION_TIME_FLOAT
00069 //      + uses floats when passing session time
00070 //        < DEFAULT >
00071 //
00072 // - DN_SESSION_TIME_INT64
00073 //      + uses __int64 when passing session time
00074 //-------------------------------------------------
00075 
00076 
00077 //-------------------------------------------------
00078 //-------------------------------------------------
00079 #define DN_NONE                         0x0000
00080 #define DN_DEFAULT_PORT                 3490
00081 #define DN_INVALID_NETID                (DWORD)(-1)
00082 
00083 //-------------------------------------------------
00084 class deConnection;
00085 //-------------------------------------------------
00086 
00087 //-------------------------------------------------
00088 // deNetUser typedef
00089 //-------------------------------------------------
00090 typedef DWORD hNetUser;
00091 
00092 //-------------------------------------------------
00093 // deNetAddress
00094 //-------------------------------------------------
00095 typedef class DENET_API deNetAddress
00096 {
00097 public:
00098 
00099     deNetAddress(void);
00100     deNetAddress( DWORD pIP, DWORD pPort, const char * pIPStr, const char * pName );
00101     ~deNetAddress(void);
00102 
00103     const char *        GetAddressIPStr(void)   const   { return m_strAddress; }
00104     DWORD               GetAddressIP(void)      const   { return m_dwAddress; }
00105     const char *        GetAddressName(void)    const   { return m_strName; }
00106     DWORD               GetPort(void)           const   { return m_dwPort; }
00107 
00108 protected:
00109 
00110     DWORD       m_dwPort;
00111     DWORD       m_dwAddress;
00112     char        m_strAddress[16];
00113     char        m_strName[16];
00114 
00115 } deNetAddress, *pdeNetAddress;
00116 
00117 
00118 //-------------------------------------------------
00119 // deConnectionDesc
00120 //-------------------------------------------------
00121 class DENET_API deConnectionDesc
00122 {
00123 public:
00124     deConnectionDesc(void)
00125     {
00126         m_dwFlags           = NULL;
00127         m_SessionID         = NULL;
00128         m_hLocalUser        = DN_INVALID_NETID;
00129         m_hRemoteUser       = DN_INVALID_NETID;
00130         m_iLocalUserType    = -1;
00131         m_iRemoteUserType   = -1;
00132         m_NetVersion        = 0.0f;
00133     }
00134     ~deConnectionDesc(void) { }
00135 
00136     DWORD           m_dwFlags;
00137     DWORD           m_SessionID;
00138     char            m_SessionName[32];
00139     deNetAddress    m_LocalAddress;
00140     DWORD           m_hLocalUser;
00141     int             m_iLocalUserType;
00142     deNetAddress    m_RemoteAddress;
00143     DWORD           m_hRemoteUser;
00144     int             m_iRemoteUserType;
00145     char            m_AppName[32];
00146     float           m_NetVersion;
00147 };
00148 
00149 //-------------------------------------------------
00150 // deNet errors thrown
00151 //-------------------------------------------------
00152 typedef enum eNetError
00153 {
00154     CODE_GENERIC_ERROR                  = -9999,
00155     CODE_INVALID_PARAM,
00156     CODE_UNSUPPORTED_VERSION,
00157     CODE_WINSOCK_ERROR,
00158     CODE_TOO_MANY_CONNECTIONS,
00159     CODE_CONNECTION_REFUSED,
00160     CODE_INVALID_CONNECTION,
00161     CODE_MASTER_SERVER_MUST_ASSIGN_NET_ID,
00162     CODE_UNABLE_TO_CREATE_CONNECTION,
00163     CODE_RESOURCE_ERROR,
00164     CODE_NOT_SUPPORTED_BY_OBJECT,
00165     CODE_INVALID_NET_ID,
00166     CODE_OK                             = 0,
00167 
00168 } eNetError;
00169 
00170 //-------------------------------------------------
00171 // deConnectionServerTime
00172 //-------------------------------------------------
00173 struct deConnectionServerTime
00174 {
00175     DWORD           dwFlags;
00176     WORD            iUpdateID;
00177 
00178 #ifdef DN_SESSION_TIME_INT64
00179     s64             Time;
00180 #else
00181     float           Time;
00182 #endif
00183 };
00184 
00185 //-------------------------------------------------
00186 // deConnectionPing
00187 //-------------------------------------------------
00188 struct deConnectionPing
00189 {
00190     enum eFlags
00191     {
00192         FLAG_KEEPALIVE          = 0x0001,
00193         FLAG_CONFIRM_NET_ID     = 0x0002,
00194         FLAG_RETURN_PING        = 0x0004,
00195     };
00196 
00197     DWORD           dwFlags;
00198     hNetUser        hNetID;
00199 
00200 #ifdef DN_SESSION_TIME_INT64
00201     s64             fTimeSent;
00202     s64             fTimeRecieved;
00203 #else
00204     float           fTimeSent;
00205     float           fTimeRecieved;
00206 #endif
00207 };
00208 
00209 //-------------------------------------------------
00210 // deConnectionDisconnect
00211 //-------------------------------------------------
00212 struct deConnectionDisconnect
00213 {
00214     enum eReason
00215     {
00216         //REASON_UNKNOWN,
00217         REASON_CONNECT_CLOSED_BY_NETUSER,
00218         REASON_SERVER_SHUTTING_DOWN,
00219         REASON_SERVER_ERROR,
00220     };
00221 
00222     eReason         Reason;
00223 };
00224 
00225 //-------------------------------------------------
00226 // deConnectionHandshake
00227 //-------------------------------------------------
00228 struct deConnectionHandshake
00229 {
00230     hNetUser        hNetID;
00231     hNetUser        hAssignedID;
00232     int             iConnectionType;
00233     int             iUserType;
00234     bool            bRequestReturnID;
00235 };
00236 
00237 //-------------------------------------------------
00238 // deConnectionLost
00239 //-------------------------------------------------
00240 struct deConnectionLost
00241 {
00242     enum eReason
00243     {
00244         //REASON_UNKNOWN,
00245         REASON_CONN_REMOTE_LOST,
00246         REASON_CONN_CLOSED,
00247         REASON_CONN_LOCAL_ERROR,
00248     };
00249 
00250     deConnection *  pConn;
00251     eReason         Reason;
00252 };
00253 
00254 //-------------------------------------------------
00255 // deConnectionRequest
00256 //-------------------------------------------------
00257 struct deConnectionRequest
00258 {   
00259     deNetAddress    Address;
00260     hNetUser        hUserID;
00261     int             iUserType;
00262     int             iProviderType;
00263 };
00264 
00265 //-------------------------------------------------
00266 // deConnectionReply
00267 //-------------------------------------------------
00268 struct deConnectionReply
00269 {
00270     enum eReason
00271     {
00272         //REASON_UNKNOWN,
00273         REASON_INVALID_ID,
00274         REASON_SERVER_FULL,
00275         REASON_REMOTE_ERROR,
00276         REASON_LOCAL_ERROR,
00277         REASON_INVALID_PERMISSIONS
00278     };
00279 
00280     deNetAddress    ServerAddress;
00281     int             iServerUserType;
00282     int             iServerProviderType;
00283     hNetUser        hServerID;
00284     hNetUser        hAssignedID;
00285     bool            bAccepted;
00286     DWORD           dwReason;
00287 };
00288 
00289 //---------------------------------------------------------------------------
00290 // deNet debug funtions
00291 //---------------------------------------------------------------------------
00292 #ifdef  _DEBUG
00293  // assert includes
00294  #include   <ASSERT.H>
00295  #define    deASSERT assert 
00296  #define    NET_ERROR( a )      deNetDlg( deNetErrorStr( a, __FILE__, __LINE__ ) )
00297  #define    NET_MSG( a )        deNetDlg( a )
00298  #define    NET_LOG_START()     deNetLogStart()
00299  #define    NET_LOG_STOP()      deNetLogStop()
00300  #define    NET_LOG( a )        deNetLog( a )
00301  #define    NET_LOG_ERROR( a )  deNetLog( deNetErrorStr( a, __FILE__, __LINE__ ) )
00302 #else
00303  #define    deASSERT
00304  #define    NET_ERROR( a )      0L
00305  #define    NET_MSG( a )        0L
00306  #define    NET_LOG_START()     0L
00307  #define    NET_LOG_STOP()      0L
00308  #define    NET_LOG( a )        0L
00309  #define    NET_LOG_ERROR( a )  0L
00310 #endif
00311 
00312 struct _iobuf;
00313 typedef _iobuf FILE;
00314 
00315 const char *    deNetErrorStr( eNetError err, const char * pFile = NULL, int iLine = -1 );
00316 void            deNetDlg( const char * pStr );
00317 void            deNetLog( const char * pStr );
00318 void            deNetLogStart( FILE * pFile = NULL );
00319 void            deNetLogStop( void );
00320 //---------------------------------------------------------------------------
00321 
00322 
00323 // forward decl
00324 //-------------------------------------------------
00325 class deNetUser;
00326 class deThreadPool;
00327 class deConnection;
00328 
00329 //*************************************************************************
00330 //-------------------------------------------------------------------------
00331 // deNet functions
00332 //-------------------------------------------------------------------------
00333 //*************************************************************************
00334 
00335 //-------------------------------------------------------------------------
00336 // <function> deNet_SetOnLogHandler( DWORD (* pProcess)( const char * ) )
00337 //-------------------------------------------------------------------------
00338 DENET_API void  deNet_SetOnLogHandler( DWORD (* pProcess)( const char * ) );
00339 
00340 //-------------------------------------------------------------------------
00341 // <function> deNet_GetTime
00342 //-------------------------------------------------------------------------
00343 #ifdef DN_SESSION_TIME_INT64
00344  DENET_API s64 deNet_GetTime( void );
00345 #else
00346  DENET_API float deNet_GetTime( void );
00347 #endif
00348 
00349 //-------------------------------------------------------------------------
00350 // <function> deNet_CreateConnection
00351 //-------------------------------------------------------------------------
00352 DENET_API eNetError deNet_CreateConnection( deConnection ** pOut, int iType, DWORD dwFlags = NULL );
00353 
00354 //-------------------------------------------------------------------------
00355 // <function> deNet_SetAppName 
00356 //-------------------------------------------------------------------------
00357 DENET_API eNetError deNet_SetAppName( const char * pName );
00358 
00359 //-------------------------------------------------------------------------
00360 // <function> deNet_GetAppName
00361 //-------------------------------------------------------------------------
00362 DENET_API const char * deNet_GetAppName( void );
00363 
00364 //-------------------------------------------------------------------------
00365 // <function> deNet_GetVersion
00366 //-------------------------------------------------------------------------
00367 DENET_API DWORD deNet_GetVersion(void);
00368 
00369 //-------------------------------------------------------------------------
00370 // <function> deNet_GetPort
00371 //-------------------------------------------------------------------------
00372 DENET_API DWORD deNet_GetPort(void);
00373 
00374 //-------------------------------------------------------------------------
00375 // <function> deNet_GetThreadPool
00376 //-------------------------------------------------------------------------
00377 DENET_API deThreadPool * deNet_GetThreadPool(void);
00378 
00379 //-------------------------------------------------------------------------
00380 // <function> deNet_GetMaxConnections
00381 //-------------------------------------------------------------------------
00382 DENET_API DWORD deNet_GetMaxConnections(void);
00383 
00384 //-------------------------------------------------------------------------
00385 // <function> deNet_GetMaxConnectionBins
00386 //-------------------------------------------------------------------------
00387 DENET_API WORD deNet_GetMaxConnectionBins(void);
00388 
00389 //-------------------------------------------------------------------------
00390 // <function> deNet_Startup
00391 //-------------------------------------------------------------------------
00392 DENET_API eNetError deNet_Startup( DWORD iMaxConnections, DWORD iMaxConnectionBins, DWORD dwPort = DN_DEFAULT_PORT, DWORD dwFlags = NULL );
00393 
00394 //-------------------------------------------------------------------------
00395 // <fucntion> deNet_Shutdown
00396 //-------------------------------------------------------------------------
00397 DENET_API eNetError deNet_Shutdown( DWORD dwFlags = NULL );
00398 
00399 
00400 #endif

Generated on Mon Sep 12 19:58:32 2005 for Destiny3D by doxygen1.3-rc3